package com.db.history.files;

import com.db.services.Settings;

import java.io.*;

/**
 * Created by Student on 26.11.2014.
 */
public class BufferedMessageWriter {

    private BufferedWriter out;

    public BufferedMessageWriter() throws IOException {
        init();
    }

    private void init() throws IOException {
        File file = new File(Settings.FILE_NAME);

        if (!file.exists()) {
            file.createNewFile();
        }
        out = new BufferedWriter(new FileWriter(file), Settings.BUFFER_SIZE);
    }


    public void addMessage(String message) throws IOException {
        while (out == null)
            init();
        out.write(message + "\n");
    }


    public void closeFile() throws IOException {
        out.close();
    }

    public void flush() throws IOException {
        out.flush();
    }

}
